<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta charset="utf-8"/>
    <title>zlt</title>
    <script type="text/javascript" th:src="@{/js/jquery-3.2.1.min.js}"></script>
    <script type="text/javascript" th:src="@{/js/oauth.js}"></script>
</head>
<body>
<script>
    //url获取state
    let state = getQueryVariable('state');
    let localState = localStorage.getItem("state");
    //判断state防止CSRF攻击
    if (localState !== state) {
        alert("state状态不一样，您可能存在非法攻击")
    }
    //url获取code
    let code = getQueryVariable('code');

    //获取token和用户信息
    $.ajax({
        url: thirdAppBackPath + 'token/' + code, success: function (result) {
            console.log("获取token返回结果:" + result.message)
            if (result.status > 200) {
                alert(result.message);
                return;
            }
            localStorage.setItem('access_token', result.access_token);
            localStorage.setItem('refresh_token', result.refresh_token);
            localStorage.setItem('account', result.account);
            localStorage.setItem('roles', result.roles);
            window.location = localStorage.getItem('visitUri');
        }
    });
</script>
</body>
</html>
